package com.example.tabbar.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.tabbar.adapter.RecipeAdapter
import com.example.tabbar.databinding.FragmentModeRecipeBinding
import com.example.tabbar.room.entity.Recipe


class ModeRecipeFragment : Fragment() {
    private var binding: FragmentModeRecipeBinding? = null
    private var recyclerView: RecyclerView? = null
    private var adapter: RecipeAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentModeRecipeBinding.inflate(inflater, container, false)
        return binding!!.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        recyclerView = binding!!.recipeRecyclerView
        adapter = RecipeAdapter()
        recyclerView!!.adapter = adapter
        recyclerView?.layoutManager = LinearLayoutManager(requireContext())
        recyclerView?.addItemDecoration(
            DividerItemDecoration(requireContext(),
                DividerItemDecoration.VERTICAL)
        )
        val list = createGroup()

        adapter?.setItems(list)

    }

    private fun createGroup() : List<Recipe> {
        val list =
        listOf(Recipe(1, "Group 1"))
        return list
    }

    companion object {

        @JvmStatic
        fun newInstance() =
            ModeRecipeFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}